<?php
class Stats_model extends Model {

    function Model_name()
    {
        parent::Model();
    }

    function get_stats()
    {
        $sql = "SELECT * FROM stats ORDER BY id DESC LIMIT 1;";
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    
    function set_stats($total_solved, $total_helping, $total_waiting, $total_calls)
    {
        $esc_total_solved = $this->db->escape($total_solved);
        $esc_total_helping = $this->db->escape($total_helping);
        $esc_total_waiting= $this->db->escape($total_waiting);
        $esc_total_calls = $this->db->escape($total_calls);
        $sql = "INSERT INTO stats (total_solved, total_helping, total_waiting, total_calls) VALUES ($esc_total_solved,$esc_total_helping,$esc_total_waiting,$esc_total_calls) ;";
        $query = $this->db->query($sql);
    }

    function vejez()
    {
        $sql = "SELECT (now() - timestamp) as vejez FROM (SELECT timestamp FROM stats ORDER BY id DESC limit 1) t;";
        $query = $this->db->query($sql);
        return $query->row('vejez');
    }

}
?>
